home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-06 | 54.3 KB | 1,551 lines |
- Newsgroups: comp.sources.misc
- From: dan%step.uucp@uunet.uu.net (Daniel Weaver)
- Subject: v25i027: ted - Terminfo/termcap test program, Part02/07
- Message-ID: <1991Nov6.041550.4839@sparky.imd.sterling.com>
- X-Md4-Signature: dc1c4a30e7cf5b0a2e9e362610d95c16
- Date: Wed, 6 Nov 1991 04:15:50 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: dan%step.uucp@uunet.uu.net (Daniel Weaver)
- Posting-number: Volume 25, Issue 27
- Archive-name: ted/part02
- Environment: UNIX
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # If this archive is complete, you will see the following message at the end:
- # "End of archive 2 (of 7)."
- # Contents: pad.c sysdep.c
- # Wrapped by dan@step on Fri Nov 1 11:28:24 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'pad.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'pad.c'\"
- else
- echo shar: Extracting \"'pad.c'\" \(40122 characters\)
- sed "s/^X//" >'pad.c' <<'END_OF_FILE'
- X/*
- X** This software is Copyright (c) 1991 by Daniel Weaver.
- X**
- X** Permission is hereby granted to copy, distribute or otherwise
- X** use any part of this package as long as you do not try to make
- X** money from it or pretend that you wrote it. This copyright
- X** notice must be maintained in any copy made.
- X**
- X** Use of this software constitutes acceptance for use in an AS IS
- X** condition. There are NO warranties with regard to this software.
- X** In no event shall the author be liable for any damages whatsoever
- X** arising out of or in connection with the use or performance of this
- X** software. Any use of this software is at the user's own risk.
- X**
- X** If you make modifications to this software that you feel
- X** increases it usefulness for the rest of the community, please
- X** email the changes, enhancements, bug fixes as well as any and
- X** all ideas to me. This software is going to be maintained and
- X** enhanced as deemed necessary by the community.
- X*/
- X/* test the pad counts on the terminal */
- X
- X#include "curses.h"
- X#include "ted.h"
- X
- X#define SELECT1(a) (!cap_select || strcmp(cap_select, a) == 0)
- X
- Xstatic char every_line[] = "This text should be on every line.";
- Xstatic char all_lines[] = "All lines should be the same. ";
- Xstatic char above_line[] = "The above line should be all X's. ";
- Xchar letters[] = "AbCdefghiJklmNopQrStuVwXyZ";
- X
- Xstatic char *clr_test_name[CLEAR_TEST_MAX] = {
- X "full page", "sparse page", "short lines", "one full line",
- X "one short line"};
- X
- Xstatic char **DF_scroll_forward, **DF_newline;
- Xstatic char **DF_cursor_left, **DF_tab;
- X
- X#ifdef ACCO
- XFILE *fpacco;
- X#endif
- X
- Xstatic void
- Xloop_test(cap, name, long_name)
- Xchar **cap, *name, *long_name;
- X { /* exercise one capability (a common case) */
- X int i;
- X
- X if (begin_test(cap, name, long_name, NULL, FALSE))
- X do {
- X go_home();
- X do {
- X page_loop();
- X for (i = 1; i < columns; i++) {
- X char_max -= pad_sent; ++ops;
- X putp(*cap); putchp(letter);
- X if (char_sent > char_max) break;
- X }
- X } while (char_sent < char_max);
- X home_down();
- X } while(end_test(NULL, 0));
- X }
- X
- X
- Xstatic void
- Xclear_pad(is_clear)
- Xint is_clear;
- X { /* run the clear screen tests (also clear-to-end-of-screen) */
- X char *end_message;
- X int j, k;
- X
- X for (j = 0; j < CLEAR_TEST_MAX; j++) clr_test_value[j] = 32767;
- X clear_select = auto_right_margin ? 0 : 1;
- X skip_next = FALSE;
- X#ifdef SVR3
- X if (enter_am_mode)
- X {
- X putp(enter_am_mode);
- X clear_select = 0;
- X }
- X#endif
- X augment = is_clear ? lines : lines - 1;
- X for ( ; clear_select < CLEAR_TEST_MAX; clear_select++) {
- X do {
- X if (augment > lines || is_clear || !cursor_address)
- X augment = lines;
- X else
- X {
- X if (augment <= 1) augment = 2;
- X if (augment < lines)
- X {
- X put_clear();
- X ptext("This line should not be erased (ed)");
- X }
- X }
- X short_subject(reps = augment);
- X switch (clear_select) {
- X case 0:
- X end_message = "All the dots should line up. ";
- X if (reps > rated_lines) reps = rated_lines;
- X break;
- X case 1:
- X end_message = "\r\n";
- X if (cursor_down) break;
- X clear_select++;
- X case 2:
- X end_message = "\r\n";
- X if (newline) break;
- X clear_select++;
- X case 3:
- X case 4:
- X end_message = "\r\n";
- X break;
- X }
- X while(char_sent < char_max) {
- X if (is_clear) put_clear();
- X else
- X {
- X if (augment == lines) go_home();
- X else tputs(tcup(cursor_address,
- X lines - reps, 0),
- X lines - reps, putch);
- X tputs(clr_eos, reps, putch);
- X }
- X char_max -= pad_sent; ++ops;
- X switch (clear_select) {
- X case 0: /* full screen test */
- X for (j = 1; j < reps; j++) {
- X for (k = 0; k < columns; k++)
- X if (k & 0xF) put_this(letter);
- X else put_this('.');
- X }
- X break;
- X case 1: /* sparse screen test */
- X for (j = columns - reps; j > 2; j--)
- X put_this(letter);
- X for (j = 2; j < reps; j++) {
- X putp(cursor_down);
- X put_this(letter);
- X }
- X break;
- X case 2: /* short lines */
- X for (j = 2; j < reps; j++) {
- X put_this(letter);
- X putp(newline);
- X }
- X put_this(letter);
- X break;
- X case 3: /* one full line */
- X for (j = columns - 5; j > 1; j--)
- X put_this(letter);
- X break;
- X case 4: /* one short line */
- X put_str("Erase this!");
- X break;
- X }
- X NEXT_LETTER;
- X }
- X } while(end_test(end_message, 1));
- X if (clear_select < CLEAR_TEST_MAX && time_pad && enq_ack()) ;
- X if (skip_next | stop_testing) break;
- X }
- X k = 0;
- X for (j = 0; j < CLEAR_TEST_MAX; j++) {
- X if (clr_test_value[j] != 32767)
- X {
- X k++;
- X sprintf(temp, "(%s) %s", current_test, clr_test_name[j]);
- X ptext(temp);
- X put_dec(" %d.%d milliseconds", clr_test_value[j]);
- X sprintf(temp, " %d reps", clr_test_reps[j]);
- X ptext(temp);
- X put_crlf();
- X }
- X }
- X if (k) (void) wait_here();
- X}
- X
- X
- Xstatic void
- Xsetup_cap(n1, v1, nn, vn)
- Xchar *n1, **v1, *nn, **vn;
- X { /* select single or multiple caps for (ind) (ri) (il) (dl) */
- X if (!*vn || (*v1 && augment == 1))
- X {
- X ced_name[0] = n1;
- X ced_value[0] = v1;
- X reps = 0;
- X augment = 1;
- X }
- X else
- X {
- X if (augment >= lines) augment = lines - 1;
- X ced_name[0] = nn;
- X ced_value[0] = vn;
- X reps = augment;
- X }
- X capper = enter_cap(current_test = ced_name[0], *ced_value[0]);
- X milli_pad = cap_list[capper].cur_plain;
- X milli_reps = cap_list[capper].cur_star;
- X sprintf(done_test, "Done. (%s)", current_test);
- X short_subject(reps);
- X }
- X
- X
- Xstatic void
- Xrin_pad()
- X { /* test reverse scroll */
- X int i;
- X
- X if (begin_test(&parm_rindex, "rin", "scroll reverse n lines",
- X NULL, FALSE)) augment = lines - 1;
- X else
- X if (begin_test(&scroll_reverse, "ri", "scroll reverse",
- X "rin", FALSE)) augment = 1;
- X else return;
- X
- X do {
- X setup_cap("ri", &scroll_reverse, "rin", &parm_rindex);
- X go_home();
- X for (i = 1; char_sent < char_max; ++i) {
- X char_max -= pad_sent; ++ops;
- X sprintf(temp, "%d\r", i);
- X put_str(temp);
- X if (scroll_reverse && augment == 1)
- X putp(scroll_reverse);
- X else tputs(tparm(parm_rindex, reps), reps, putch);
- X }
- X put_str("This line should be on the bottom.\r");
- X if (scroll_reverse && augment == 1)
- X for (i = 1; i < lines; i++) {
- X ++ops;
- X putp(scroll_reverse);
- X }
- X else tputs(tparm(parm_rindex, lines - 1), lines - 1, putch);
- X sprintf(temp, "\nScroll reverse %d line%s. ", augment,
- X augment == 1 ? "" : "s");
- X } while(end_test(temp, 1));
- X }
- X
- X
- Xstatic void
- Xil_pad()
- X { /* test insert line */
- X int i;
- X
- X if (begin_test(&parm_insert_line, "il", "insert n lines",
- X NULL, TRUE)) augment = lines - 1;
- X else
- X if (begin_test(&insert_line, "il1", "insert line", "il", FALSE))
- X augment = 1;
- X else return;
- X
- X do {
- X setup_cap("il1", &insert_line, "il", &parm_insert_line);
- X go_home();
- X for (i = 1; char_sent < char_max; ++i) {
- X char_max -= pad_sent; ++ops;
- X sprintf(temp, "%d\r", i);
- X put_str(temp);
- X if (reps)
- X tputs(tparm(parm_insert_line, reps), reps, putch);
- X else putp(insert_line);
- X }
- X put_str("This line should be on the bottom.\r");
- X if (reps)
- X tputs(tparm(parm_insert_line, lines - 1), lines - 1, putch);
- X else
- X for (i = 1; i < lines; i++) {
- X ++ops;
- X putp(insert_line);
- X }
- X sprintf(temp, "Insert %d line%s. ", augment,
- X augment == 1 ? "" : "s");
- X } while(end_test(temp, 1));
- X }
- X
- X
- Xstatic void
- Xindn_pad()
- X { /* test scroll forward */
- X int i;
- X
- X if (begin_test(&parm_index, "indn", "scroll n lines",
- X NULL, FALSE)) augment = lines - 1;
- X else
- X if (begin_test(DF_scroll_forward, "ind", "scroll forward",
- X "indn", FALSE)) augment = 1;
- X else return;
- X
- X do {
- X setup_cap("ind", DF_scroll_forward, "indn", &parm_index);
- X /* go to the bottom of the screen */
- X home_down();
- X for (i = 1; char_sent < char_max; ++i) {
- X char_max -= pad_sent; ++ops;
- X sprintf(temp, "%d\r", i);
- X put_str(temp);
- X if (augment > 1)
- X tputs(tparm(parm_index, reps), reps, putch);
- X else
- X put_ind();
- X }
- X put_str("This line should be on the top.\r");
- X if (augment == 1)
- X for (i = 1; i < lines; i++) {
- X ++ops;
- X put_ind();
- X }
- X else tputs(tparm(parm_index, lines - 1), lines - 1, putch);
- X go_home();
- X sprintf(temp, "\nScroll forward %d line%s. ", augment,
- X augment == 1 ? "" : "s");
- X } while(end_test(temp, 1));
- X }
- X
- X
- Xstatic void
- Xdl_pad()
- X { /* test delete lines */
- X int i;
- X
- X if (begin_test(&parm_delete_line, "dl", "delete n lines",
- X NULL, TRUE)) augment = lines - 1;
- X else
- X if (begin_test(&delete_line, "dl1", "delete line", "dl", TRUE))
- X augment = 1;
- X else return;
- X
- X do {
- X setup_cap("dl1", &delete_line, "dl", &parm_delete_line);
- X go_home();
- X for (i = 0; char_sent < char_max; ++i) {
- X char_max -= pad_sent; ++ops;
- X sprintf(temp, "%d\r", i);
- X if ((i & 0x7f) == 0 && augment < lines - 1)
- X {
- X go_home();
- X putln(temp);
- X }
- X put_str(temp);
- X if (reps) tputs(delete_line, reps, putch);
- X else putp(delete_line);
- X }
- X home_down();
- X put_str("This line should be on the top.");
- X go_home();
- X if (reps)
- X tputs(tparm(parm_delete_line, lines - 1), lines - 1, putch);
- X else
- X for (i = 1; i < lines; i++) {
- X ++ops;
- X putp(delete_line);
- X }
- X sprintf(temp, "\nDelete %d line%s. ", augment,
- X augment == 1 ? "" : "s");
- X } while(end_test(temp, 1));
- X }
- X
- X
- Xvoid
- Xtest_pad(cap)
- Xchar *cap; /* capability to be tested, NULL if test all */
- X {
- X int i, j, k, l, csr_not_tested, hzcc;
- X int scroll_chars, scroll_ms_delay;
- X char *s;
- X
- X if (tty_can_sync == 1) verify_time();
- X control_init();
- X put_clear();
- X
- X cap_tested = 0; cap_select = cap;
- X hzcc = columns * 8 / 10; /* horizontal character count */
- X
- X /* set up default caps for translate mode */
- X DF_tab = translate_mode ? &tab : &TM_tab;
- X DF_newline = (translate_mode && newline) ? &newline : &TM_newline;
- X DF_cursor_left = (translate_mode && cursor_left)
- X ? &cursor_left : &TM_cursor_left;
- X#ifdef SVR3
- X DF_scroll_forward = ((translate_mode && scroll_forward)
- X || over_strike) ? &scroll_forward : &TM_scroll_forward;
- X#else
- X DF_scroll_forward = (translate_mode && scroll_forward)
- X ? &scroll_forward : &TM_scroll_forward;
- X#endif
- X
- X#ifdef ACCO
- X /* open the results file for multi_test() */
- X fpacco = fopen("ted.acco", "w");
- X#endif
- X
- X /* findout how much the scroll delay will effect the results */
- X capper = enter_cap("ind", *DF_scroll_forward);
- X milli_pad = scroll_ms_delay = cap_list[capper].cur_plain;
- X short_subject(0);
- X scroll_chars = pad_sent;
- X
- X if (reset_1string)
- X loop_test(&reset_1string, "rs1", "reset string 1");
- X if (reset_2string)
- X loop_test(&reset_2string, "rs2", "reset string 2");
- X if (reset_3string)
- X loop_test(&reset_3string, "rs3", "reset string 3");
- X
- X#ifdef SVR3
- X /* the reset strings may dink with the XON/XOFF modes */
- X if (select_xon_xoff == 0 && exit_xon_mode) putp(exit_xon_mode);
- X if (select_xon_xoff == 1 && enter_xon_mode) putp(enter_xon_mode);
- X#endif
- X if (init_1string)
- X loop_test(&init_1string, "is1", "init string 1");
- X if (init_2string)
- X loop_test(&init_2string, "is2", "init string 2");
- X if (init_3string)
- X loop_test(&init_3string, "is3", "init string 3");
- X
- X#ifdef SVR3
- X can_test("(rmxon)(smxon)");
- X if (select_xon_xoff == 0 && exit_xon_mode)
- X if (SELECT1("rmxon"))
- X loop_test(&exit_xon_mode, "rmxon", "exit xon/xoff mode");
- X else putp(exit_xon_mode);
- X if (select_xon_xoff == 1 && enter_xon_mode) putp(enter_xon_mode);
- X#endif
- X can_test("(smcup)(rmcup)");
- X if (enter_ca_mode) putp(enter_ca_mode);
- X
- X if (!can_clear_screen && !stop_testing)
- X {
- X ptextln("(clear) clear screen not present");
- X ptext("pad processing terminated...");
- X (void) wait_here();
- X return;
- X }
- X
- X if (can_go_home && auto_right_margin &&
- X multi_test(NULL, FALSE, 1, 0, 0, 1, "home", &cursor_home))
- X {
- X /* truly brain damaged terminals will fail this test
- X because they cannot accept data at full rate */
- X capper = -2;
- X do {
- X while(char_sent < char_max) {
- X go_home();
- X for (j = 1; j < rated_lines; j++) {
- X for (k = 0; k < columns; k++)
- X if (k & 0xF) put_this(letter);
- X else put_this('.');
- X }
- X ops += (lines - 1) + columns;
- X NEXT_LETTER;
- X }
- X } while(end_test("All the dots should line up. ", 1));
- X }
- X if (can_go_home &&
- X multi_test(NULL, FALSE, 1, 0, 4, 2,
- X "home", &cursor_home, "nel", DF_newline))
- X do {
- X while(char_sent < char_max) {
- X go_home();
- X for (j = 1; j < rated_lines; j++) {
- X char_max -= pad_sent; ++ops;
- X for (k = 2; k < columns; k++)
- X if (k & 0xF) putchp(letter);
- X else putchp('.');
- X put_crlf();
- X }
- X NEXT_LETTER;
- X }
- X } while(end_test("All the dots should line up. ", 1));
- X if (begin_test(&clear_screen, "clear", "clear screen",
- X NULL, FALSE)) clear_pad(TRUE);
- X if (begin_test(&clr_eos, "ed", "clear to end of screen",
- X NULL, FALSE)) clear_pad(FALSE);
- X augment = hzcc;
- X if (begin_test(&erase_chars, "ech", "erase characters",
- X NULL, FALSE))
- X do {
- X go_home();
- X if (augment > columns - 2) augment = columns - 2;
- X short_subject(reps = augment);
- X for (i = 2; i < lines; i++) {
- X char_max -= pad_sent; ++ops;
- X for (j = 0; j <= reps; j++) putchp(letter);
- X put_cr();
- X tputs(tparm(erase_chars, reps), reps, putch);
- X put_crlf();
- X if (test_count == 0 && char_sent > char_max) break;
- X }
- X for (i = 1; i <= reps; i++) putchp(' ');
- X putchp(letter); put_crlf();
- X NEXT_LETTER;
- X } while(end_test(all_lines, 0));
- X#ifdef SVR3
- X augment = hzcc;
- X if (begin_test(&clr_bol, "el1", "clear to beginning of line",
- X NULL, TRUE) &&
- X acco_pad("cub1", *DF_cursor_left) &&
- X acco_pad("cub1", *DF_cursor_left) &&
- X acco_pad("nel", *DF_newline))
- X do {
- X go_home();
- X if (augment > columns - 2) augment = columns - 2;
- X short_subject(reps = augment);
- X for (i = 2; i < lines; i++) {
- X char_max -= pad_sent; ++ops;
- X for (j = 0; j <= reps; j++) putchp(letter);
- X putp(*DF_cursor_left);
- X putp(*DF_cursor_left);
- X tputs(clr_bol, reps, putch);
- X put_crlf();
- X if (test_count == 0 && char_sent > char_max) break;
- X }
- X for (i = 1; i <= reps; i++) putchp(' ');
- X putchp(letter); put_crlf();
- X NEXT_LETTER;
- X } while(end_test(all_lines, 0));
- X#endif
- X augment = hzcc / 10;
- X if (begin_test(&clr_eol, "el", "clear to end of line",
- X NULL, FALSE) && acco_pad("nel", *DF_newline))
- X do {
- X go_home();
- X if (augment > hzcc) augment = hzcc;
- X for (i = 2; i < lines; i++) {
- X char_max -= pad_sent; ++ops;
- X for (j = -1; j < augment; j++) putchp(letter);
- X put_cr();
- X putchp(letter);
- X putp(clr_eol);
- X put_crlf();
- X if (test_count == 0 && char_sent > char_max) break;
- X }
- X putchp(letter); put_crlf();
- X NEXT_LETTER;
- X } while(end_test(all_lines, 0));
- X if (multi_test("(smdc) or (rmdc) delete mode", FALSE, 0, 7, 6, 2,
- X "smdc", &enter_delete_mode,
- X "rmdc", &exit_delete_mode))
- X do {
- X page_loop();
- X for (i = 1; i < columns; i++) {
- X char_max -= pad_sent; ++ops;
- X putp(enter_delete_mode);
- X putp(exit_delete_mode);
- X putchp(letter);
- X }
- X if (char_sent > char_max) home_down();
- X } while(end_test(NULL, 0));
- X augment = hzcc;
- X if (multi_test("(dch) delete characters", TRUE, 4, 0, 14, 3,
- X "smdc", &enter_delete_mode, "dch", &parm_dch,
- X "rmdc", &exit_delete_mode) &&
- X acco_pad(NULL, *DF_newline))
- X {
- X do {
- X if (augment > hzcc) augment = hzcc;
- X short_subject(reps = augment);
- X go_home();
- X for (i = 2; i < lines; i++) {
- X char_max -= pad_sent; ++ops;
- X for (j = 0; j <= reps; j++) putchp(letter);
- X put_cr();
- X putp(enter_delete_mode);
- X tputs(tparm(parm_dch, reps), reps, putch);
- X putp(exit_delete_mode);
- X put_crlf();
- X if (test_count == 0 && char_sent > char_max) break;
- X }
- X putchp(letter);
- X put_crlf();
- X NEXT_LETTER;
- X } while(end_test(all_lines, 1));
- X putp(exit_delete_mode);
- X }
- X else /* no need to test both */
- X if (multi_test("(dch1) delete one character", TRUE, 0x1e, 0, 2, 4,
- X "dch1", &delete_character, "dch", &parm_dch,
- X "smdc", &enter_delete_mode, "rmdc", &exit_delete_mode))
- X do {
- X if (augment > hzcc) augment = hzcc;
- X if (augment < 1) augment = 1;
- X go_home();
- X for (i = 2; i < lines; i++) {
- X for (j = -1; j < augment; j++) putchp(letter);
- X put_cr();
- X putp(enter_delete_mode);
- X for (j = 0; j < augment; j++) {
- X char_max -= pad_sent; ++ops;
- X putp(delete_character);
- X }
- X putp(exit_delete_mode);
- X put_crlf();
- X if (test_count == 0 && char_sent > char_max) break;
- X }
- X putchp(letter); put_crlf();
- X NEXT_LETTER;
- X } while(end_test(all_lines, 0));
- X if (multi_test("(smir) or (rmir) insert mode", FALSE, 0, 7, 6, 2,
- X "smir", &enter_insert_mode,
- X "rmir", &exit_insert_mode))
- X do {
- X page_loop();
- X for (i = 1; i < columns; i++) {
- X char_max -= pad_sent; ++ops;
- X putp(enter_insert_mode);
- X putp(exit_insert_mode);
- X putchp(letter);
- X }
- X if (char_sent > char_max) home_down();
- X } while(end_test(NULL, 0));
- X augment = j = columns * 9 / 10;
- X if (multi_test("(ich) insert n characters", TRUE, 4, 0, 14, 3,
- X "smir", &enter_insert_mode,
- X "ich", &parm_ich,
- X "rmir", &exit_insert_mode) &&
- X acco_pad(NULL, *DF_newline) &&
- X acco_pad(NULL, *DF_newline))
- X {
- X do {
- X if (augment > j) augment = j;
- X short_subject(reps = augment);
- X go_home();
- X for (i = 2; i < lines; i++) {
- X char_max -= pad_sent; ++ops;
- X putchp(letter);
- X put_cr();
- X putp(enter_insert_mode);
- X replace_mode = 0;
- X tputs(tparm(parm_ich, reps), reps, putch);
- X putp(exit_insert_mode); replace_mode = 1;
- X put_crlf();
- X if (test_count == 0 && char_sent > char_max) break;
- X }
- X for (i = 0; i < reps; i++) putchp(' ');
- X putchp(letter); NEXT_LETTER;
- X put_crlf();
- X } while(end_test(all_lines, 1));
- X putp(exit_insert_mode);
- X }
- X if (multi_test("(smir) (ich1) (rmir) insert character mode",
- X FALSE, 0xC, 0x13, 0xC, 4,
- X "smir", &enter_insert_mode,
- X "ich1", &insert_character, "ip", &insert_padding,
- X "rmir", &exit_insert_mode))
- X {
- X if (!insert_padding && !insert_character)
- X {
- X (void) acco_pad(NULL, enter_insert_mode);
- X (void) acco_pad(NULL, exit_insert_mode);
- X }
- X l = columns * 9 / 10;
- X do {
- X put_clear();
- X for (i = 2; i < lines; i++) {
- X putchp(letter);
- X put_cr();
- X putp(enter_insert_mode); replace_mode = 0;
- X if (!insert_padding && !insert_character)
- X { /* only enter/exit is needed */
- X char_max -= pad_sent; ++ops;
- X for (j = 0; j < l; j++) putchp('.');
- X }
- X else
- X for (j = 0; j < l; j++) {
- X char_max -= pad_sent; ++ops;
- X putp(insert_character);
- X putchp('.'); putp(insert_padding);
- X }
- X putp(exit_insert_mode); replace_mode = 1;
- X put_crlf();
- X if (test_count == 0 && char_sent > char_max) break;
- X }
- X for (j = 0; j < l; j++) putchp('.');
- X putchp(letter); NEXT_LETTER;
- X put_crlf();
- X } while(end_test(all_lines, 0));
- X putp(exit_insert_mode);
- X }
- X if (!enter_insert_mode && !exit_insert_mode &&
- X !enter_delete_mode && !exit_delete_mode &&
- X multi_test("(ich1) or (dch1) insert/delete character",
- X FALSE, 0, 7, 6, 2,
- X "ich1", &insert_character, "dch1", &delete_character))
- X do {
- X ptext("\rThis line should not be garbled. It should be left justified.");
- X put_cr(); char_sent = 0;
- X while(char_sent < char_max) {
- X char_max -= pad_sent; ++ops;
- X putp(insert_character);
- X putp(delete_character);
- X }
- X } while(end_test("\n", 0));
- X augment = columns * 9 / 10;
- X if (begin_test(&repeat_char, "rep", "repeat character",
- X NULL, TRUE))
- X do {
- X if (augment > columns - 2) augment = columns - 2;
- X if (augment < 2) augment = 2;
- X short_subject(reps = augment);
- X do {
- X go_home();
- X for (i = 2; i < lines; i++) {
- X char_max -= pad_sent; ++ops;
- X tputs(tparm(repeat_char, letter, reps), reps, putch);
- X char_count = reps;
- X put_crlf();
- X }
- X for (j = 0; j < reps; j++) putchp(letter);
- X put_crlf(); NEXT_LETTER;
- X } while(char_sent < char_max);
- X } while(end_test(all_lines, 0));
- X if (begin_test(&cursor_address, "cup", "cursor address",
- X NULL, FALSE))
- X do { /* the delay repeat factor is probably wrong */
- X l = (columns - 4) >> 1;
- X for (i = 1; i + i + 2 < lines; i++) {
- X for (j = 0; j <= l; j++) {
- X char_max -= pad_sent; ops += 4;
- X s = tcup(cursor_address, i, j);
- X tputs(s, lines, putch); putchp(letter);
- X s = tcup(cursor_address, i, l + l + 1 - j);
- X tputs(s, l + l, putch); putchp(letter);
- X s = tcup(cursor_address, lines - i, j);
- X tputs(s, lines, putch); putchp(letter);
- X s = tcup(cursor_address, lines - i, l + l + 1 - j);
- X tputs(s, l + l, putch); putchp(letter);
- X }
- X if (char_sent > char_max) break;
- X }
- X NEXT_LETTER;
- X s = tcup(cursor_address, lines / 2, char_count = l - 6);
- X tputs(s, columns / 2, putch);
- X } while(end_test(NULL, 1));
- X if (begin_test(&down_half_line, "hd", "down half line",
- X NULL, TRUE))
- X do {
- X for (i = 1; i < columns; i += 2) {
- X for (j = 1; j < i; ++j) putchp(' ');
- X putp(down_half_line);
- X for (k = lines + lines; k > 4; k--) {
- X if (j++ >= columns) break;
- X char_max -= pad_sent; ++ops;
- X putp(down_half_line);
- X putchp(letter);
- X }
- X go_home();
- X if (char_sent > char_max) break;
- X }
- X NEXT_LETTER;
- X } while(end_test(NULL, 1));
- X if (begin_test(&up_half_line, "hu", "up half line",
- X NULL, TRUE))
- X do {
- X for (i = 1; i < columns; i += 2) {
- X home_down();
- X for (j = 1; j < i; ++j) putchp(' ');
- X putp(up_half_line);
- X for (k = lines + lines; k > 4; k--) {
- X if (j++ >= columns) break;
- X char_max -= pad_sent; ++ops;
- X putp(up_half_line);
- X putchp(letter);
- X }
- X if (char_sent > char_max) break;
- X }
- X go_home();
- X NEXT_LETTER;
- X } while(end_test(NULL, 1));
- X rin_pad();
- X indn_pad();
- X if (multi_test("(sc) or (rc) save/restore cursor",
- X FALSE, 0, 7, 6, 2,
- X "sc", &save_cursor, "rc", &restore_cursor))
- X do {
- X page_loop();
- X for (i = 1; i < columns; i++) {
- X char_max -= pad_sent; ++ops;
- X putp(save_cursor); putchp(letter);
- X putp(restore_cursor); putchp('X');
- X }
- X if (char_sent > char_max) home_down();
- X } while(end_test(above_line, 0));
- X augment = (lines + 1) / 2;
- X if (change_scroll_region &&
- X multi_test(NULL, FALSE, 1, 0, 2, 2,
- X "ind", DF_scroll_forward, "csr", &change_scroll_region))
- X {
- X do {
- X if (augment < 2) augment = 2;
- X putp(tparm(change_scroll_region, lines - augment,
- X lines - 1));
- X /* go to the bottom of the screen */
- X home_down();
- X for (i = 0; char_sent < char_max; ++i) {
- X char_max -= pad_sent; ++ops;
- X sprintf(temp, "%d\r", i);
- X put_str(temp);
- X put_ind();
- X }
- X ptextln("(csr) is broken.");
- X ++ops;
- X for (i = augment; i > 1; i--) {
- X ++ops;
- X put_ind();
- X }
- X } while(end_test(NULL, 0));
- X putp(tparm(change_scroll_region, 0, lines - 1));
- X put_clear();
- X }
- X can_test("csr");
- X csr_not_tested = 1;
- X if (save_cursor && restore_cursor && change_scroll_region &&
- X multi_test(NULL, FALSE, 1, 0, 14, 3,
- X "sc", &save_cursor,
- X "csr", &change_scroll_region,
- X "rc", &restore_cursor))
- X {
- X csr_not_tested = 0;
- X do {
- X page_loop();
- X for (i = 1; i < columns; i++) {
- X char_max -= pad_sent; ++ops;
- X putp(save_cursor); putchp(letter);
- X putp(tparm(change_scroll_region, 0, lines - 1));
- X putp(restore_cursor); putchp('X');
- X }
- X if (char_sent > char_max) home_down();
- X } while(end_test(above_line, 0));
- X /* scroll delay times will corrupt the "time_pad" test */
- X if (!time_pad || (scroll_ms_delay == 0 && enq_ack()))
- X do {
- X for (i = 0; i < lines; i++) {
- X char_max -= pad_sent; ++ops;
- X for (j = lines - i; j > 0; j--) {
- X put_crlf();
- X char_max -= scroll_chars;
- X }
- X putp(save_cursor);
- X putp(tparm(change_scroll_region, i, lines - 1));
- X putp(restore_cursor);
- X put_str(every_line);
- X }
- X putp(save_cursor);
- X putp(tparm(change_scroll_region, 0, lines - 1));
- X putp(restore_cursor);
- X } while(end_test(" ", 0));
- X }
- X if (cursor_address && change_scroll_region &&
- X (scroll_ms_delay == 0 || !time_pad) &&
- X multi_test(NULL, FALSE, 1, 0, 6, 2,
- X "cup", &cursor_address, "csr", &change_scroll_region))
- X do { /* this test uses (cup) and (ind) */
- X for (i = 0; i < lines; i++) {
- X char_max -= pad_sent; ++ops;
- X for (j = lines - i; j > 0; j--) {
- X put_crlf();
- X char_max -= scroll_chars;
- X }
- X putp(tparm(change_scroll_region, i, lines - 1));
- X s = tcup(cursor_address, lines - 1, 0);
- X tputs(s, lines, putch);
- X put_str(every_line);
- X }
- X putp(tparm(change_scroll_region, 0, lines - 1));
- X s = tcup(cursor_address, lines - 1, strlen(every_line));
- X tputs(s, lines, putch);
- X csr_not_tested = 0;
- X } while(end_test(" ", 0));
- X if (SELECT1("csr") && !stop_testing)
- X if (csr_not_tested)
- X {
- X if (change_scroll_region)
- X ptextln("(sc) (rc) (cup) missing, (csr) change_scroll_region not tested");
- X else ptextln("(csr) change_scroll_region not present");
- X if (!time_pad) (void) wait_here();
- X cap_tested = 1;
- X }
- X else /* reset the scroll region */
- X { /* just in case we screwed it up */
- X putp(tparm(change_scroll_region, 0, lines - 1));
- X home_down();
- X }
- X dl_pad();
- X il_pad();
- X if (multi_test("(il1) or (dl1) insert/delete line",
- X TRUE, 0, 7, 6, 2,
- X "il1", &insert_line, "dl1", &delete_line))
- X do {
- X putln("\rThis text is written on the first line.");
- X putln("It is followed by this sentence.");
- X putln("((((");
- X ptext("It has come to my attention that some people are");
- X ptext(" running this diagnostic without actually reading");
- X ptext(" the content of the messages printed on the");
- X ptext(" screen. This lack of regard for the literary");
- X ptext(" talent of the programmer will not be tolerated");
- X ptext(" in the future. For all you know this message");
- X ptext(" could change and you would never notice. But I");
- X ptext(" did not in fact change the message therefore it");
- X ptext(" is permissible to omit reading of this message.");
- X put_crlf();
- X i = line_count - 1;
- X go_home();
- X put_newlines(2); char_sent = 0;
- X while(char_sent < char_max) {
- X char_max -= pad_sent; ++ops;
- X putp(insert_line);
- X put_str("))))");
- X put_cr();
- X putp(delete_line);
- X }
- X put_newlines(i);
- X } while(end_test(NULL, 0));
- X if (begin_test(DF_tab, "ht", "tab", NULL, TRUE))
- X do {
- X /* it is not allways possible to test tabs with
- X caps that do not already have padding.
- X The following test uses a mixed bag of tests
- X in order to aviod this problem.
- X Note: I do not scroll */
- X if (auto_right_margin && can_go_home)
- X for (i = 1, go_home(); i < lines; i++) {
- X for (j = 8; j < columns; j += 8) {
- X char_max -= pad_sent; ++ops;
- X put_str("\t");
- X }
- X put_str("A ");
- X }
- X if (cursor_down && can_go_home)
- X for (i = 1, go_home(); i < lines; i++) {
- X for (j = 8; j < columns; j += 8) {
- X char_max -= pad_sent; ++ops;
- X put_str("\t");
- X }
- X put_str("D\r");
- X putp(cursor_down);
- X }
- X if (cursor_address)
- X for (i = 1; i < lines; i++) {
- X s = tcup(cursor_address, i - 1, 0);
- X tputs(s, lines, putch);
- X for (j = 8; j < columns; j += 8) {
- X char_max -= pad_sent; ++ops;
- X put_str("\t");
- X }
- X put_str("C");
- X }
- X go_home();
- X for (i = 1; i < lines; i++) {
- X for (j = 8; j < columns; j += 8) {
- X char_max -= pad_sent; ++ops;
- X put_str("\t");
- X }
- X putln("N");
- X }
- X } while(end_test("A-(am) D-(cud1) C-(cup) N-(nel) ", 0));
- X /* In terminals that emulate non-hidden attributes
- X with hidden attributes, the amount of time that it takes
- X to fill the screen with an attribute is nontrivial.
- X The following test is designed to catch those delays */
- X if (multi_test("(smso) or (rmso) enter/exit standout mode",
- X FALSE, 0, 7, 6, 2,
- X "smso", &enter_standout_mode, "rmso", &exit_standout_mode))
- X do {
- X page_loop();
- X j = magic_cookie_glitch > 0 ? magic_cookie_glitch : 0;
- X for (i = 2 + j + j; i < columns; ) {
- X char_max -= pad_sent; ++ops;
- X put_mode(enter_standout_mode); i += j + j + 2;
- X putchp('X');
- X put_mode(exit_standout_mode);
- X putchp('X');
- X }
- X if (char_sent > char_max) home_down();
- X } while(end_test(above_line, 0));
- X if (multi_test("(smacs) or (rmacs) enter/exit alt charset mode",
- X FALSE, 0, 7, 6, 2,
- X "smacs", &enter_alt_charset_mode,
- X "rmacs", &exit_alt_charset_mode))
- X do {
- X /* test enter even if exit is missing */
- X page_loop();
- X j = magic_cookie_glitch > 0 ? magic_cookie_glitch : 0;
- X for (i = 2 + j + j; i < columns; ) {
- X char_max -= pad_sent; ++ops;
- X put_mode(enter_alt_charset_mode);
- X i += j + j + 2;
- X putchp(letter);
- X put_mode(exit_alt_charset_mode);
- X putchp(letter);
- X }
- X if (char_sent > char_max) home_down();
- X } while(end_test(NULL, 0));
- X loop_test(&flash_screen, "flash", "flash screen");
- X loop_test(&keypad_xmit, "smkx", "keypad transmit");
- X loop_test(&keypad_local, "rmkx", "exit keypad transmit");
- X loop_test(&meta_on, "smm", "turn on meta mode");
- X loop_test(&meta_off, "rmm", "turn off meta mode");
- X
- X pad_time(clear_screen, &i, &j);
- X if (!stop_testing && clear_screen && !xon_xoff && (i + j) != 0
- X && SELECT1("clear"))
- X {
- X char *clr = liberated(clear_screen);
- X
- X ptext("If you would like to see if the terminal will really lock up.");
- X ptext(" I will send the clear screen sequence without the pads.");
- X ptext(" Type yes to trash your terminal: ");
- X milli_pad = milli_reps = char_sent = 0;
- X char_max = full_test;
- X (void) acco_pad(NULL, clear_screen);
- X if (getchp(STRIP_PARITY) == 'y')
- X do {
- X while(char_sent < char_max) {
- X char_max -= pad_sent; ++ops;
- X put_str("Erase this!");
- X putp(clr);
- X }
- X ptextln("\nIf you can read this you probably have your terminal set for xon/xoff.");
- X } while(end_test(NULL, 0));
- X }
- X#ifdef ACCO
- X /* close the results file for multi_test() */
- X if (fpacco) fclose(fpacco);
- X#endif
- X }
- END_OF_FILE
- if test 40122 -ne `wc -c <'pad.c'`; then
- echo shar: \"'pad.c'\" unpacked with wrong size!
- fi
- # end of 'pad.c'
- fi
- if test -f 'sysdep.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'sysdep.c'\"
- else
- echo shar: Extracting \"'sysdep.c'\" \(11601 characters\)
- sed "s/^X//" >'sysdep.c' <<'END_OF_FILE'
- X/*
- X** This software is Copyright (c) 1991 by Daniel Weaver.
- X**
- X** Permission is hereby granted to copy, distribute or otherwise
- X** use any part of this package as long as you do not try to make
- X** money from it or pretend that you wrote it. This copyright
- X** notice must be maintained in any copy made.
- X**
- X** Use of this software constitutes acceptance for use in an AS IS
- X** condition. There are NO warranties with regard to this software.
- X** In no event shall the author be liable for any damages whatsoever
- X** arising out of or in connection with the use or performance of this
- X** software. Any use of this software is at the user's own risk.
- X**
- X** If you make modifications to this software that you feel
- X** increases it usefulness for the rest of the community, please
- X** email the changes, enhancements, bug fixes as well as any and
- X** all ideas to me. This software is going to be maintained and
- X** enhanced as deemed necessary by the community.
- X*/
- X/*
- X * Operating system dependant functions. Such as special tty handler
- X * modes.
- X */
- X
- X#include <sys/errno.h>
- X#if defined(vax) || defined(_AIX)
- X#include <fcntl.h>
- X#else
- X#include <sys/fcntl.h>
- X#endif
- X#include <curses.h>
- X#include <signal.h>
- X#include "ted.h"
- X
- X/* The appropriate speeds for various termio settings. */
- Xint speeds[] =
- X {
- X 0, /* B0, */
- X 50, /* B50, */
- X 75, /* B75, */
- X 110, /* B110, */
- X 134, /* B134, */
- X 150, /* B150, */
- X 200, /* B200, */
- X 300, /* B300, */
- X 600, /* B600, */
- X 1200, /* B1200, */
- X 1800, /* B1800, */
- X 2400, /* B2400, */
- X 4800, /* B4800, */
- X 9600, /* B9600, */
- X 19200, /* EXTA, */
- X 38400, /* EXTB, */
- X 0,
- X };
- X
- X/* error report location for ioctl's */
- Xextern int errno;
- X
- X#ifdef ICANON /* ATT UNIX */
- X#define SLEEP(x)
- X#define TTY_IS_NOECHO !(new_modes.c_lflag & ECHO)
- X#define TTY_IS_OUT_TRANS (new_modes.c_oflag & OPOST)
- X#define TTY_IS_CHAR_MODE !(new_modes.c_lflag & ICANON)
- X
- Xstruct termio old_modes, new_modes;
- X
- Xtty_raw(minch, mask)
- Xint minch, mask;
- X { /* set tty to raw noecho */
- X new_modes = old_modes;
- X#ifdef SELECT
- X new_modes.c_cc[VMIN]=1;
- X#else
- X new_modes.c_cc[VMIN]=minch;
- X#endif
- X new_modes.c_cc[VTIME]=2;
- X new_modes.c_lflag &=
- X ~(ISIG|ICANON|XCASE|ECHO|ECHOE|ECHOK|ECHONL);
- X#ifdef LOBLK
- X new_modes.c_lflag &= ~LOBLK;
- X#endif
- X new_modes.c_oflag &= ~(OPOST|OLCUC|TABDLY);
- X if (mask == ALLOW_PARITY)
- X {
- X new_modes.c_cflag &= ~(CSIZE|PARENB|HUPCL);
- X new_modes.c_cflag |= CS8;
- X }
- X new_modes.c_iflag &=
- X ~(IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|
- X IUCLC|IXON|IXANY|IXOFF);
- X if (not_a_tty) return;
- X ioctl(fileno(stdin), TCSETAW, &new_modes);
- X }
- X
- X
- Xint
- Xtty_meta_prep()
- X { /* print a warning before the meta key test */
- X if (not_a_tty) return 0;
- X if ((old_modes.c_cflag & CSIZE) == CS8) return 0;
- X ptext("The meta key test must be run with the");
- X ptext(" terminal set for 8 data bits. Two stop bits");
- X ptext(" may also be needed for correct display. I will");
- X ptext(" transmit 8 bit data but if the terminal is set for");
- X ptext(" 7 bit data, garbage may appear on the screen.");
- X return 1;
- X }
- X
- X
- Xtty_set()
- X { /* set tty to special modes */
- X new_modes = old_modes;
- X new_modes.c_cc[VMIN]=1;
- X new_modes.c_cc[VTIME]=1;
- X new_modes.c_lflag &= ~(ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHONL);
- X new_modes.c_oflag &= ~(ONLCR|OCRNL|ONLRET|OFILL);
- X if (char_mask == ALLOW_PARITY) new_modes.c_iflag &= ~ISTRIP;
- X switch (select_xon_xoff) {
- X case 0:
- X new_modes.c_iflag &= ~(IXON|IXOFF);
- X break;
- X case 1:
- X#if sequent
- X /* the sequent System V emulation is broken */
- X new_modes = old_modes;
- X new_modes.c_cc[VEOL] = 6; /* control F (ACK) */
- X#endif
- X new_modes.c_iflag |= IXON | IXOFF;
- X break;
- X }
- X switch (select_delay_type) {
- X case 0:
- X new_modes.c_oflag &=
- X ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
- X break;
- X case 1:
- X new_modes.c_oflag &=
- X ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
- X new_modes.c_oflag |= NL1 | CR2;
- X break;
- X }
- X if (!(new_modes.c_oflag & ~OPOST)) new_modes.c_oflag &= ~OPOST;
- X if (not_a_tty) return;
- X ioctl(fileno(stdin), TCSETAW, &new_modes);
- X }
- X
- X
- Xtty_reset()
- X { /* reset the tty to the original modes */
- X fflush(stdout);
- X if (not_a_tty) return;
- X ioctl(fileno(stdin), TCSETAW, &old_modes);
- X }
- X
- X
- Xtty_init()
- X { /* ATT terminal init */
- X int flags;
- X
- X#ifdef F_GETFL
- X flags = fcntl(fileno(stdin), F_GETFL, 0);
- X nodelay_read = flags & O_NDELAY;
- X#else
- X nodelay_read = FALSE;
- X#endif
- X not_a_tty = FALSE;
- X if (ioctl(fileno(stdin), TCGETA, &old_modes) == -1)
- X {
- X if (errno == ENOTTY)
- X {
- X tty_frame_size = 20;
- X not_a_tty = TRUE;
- X return;
- X }
- X printf("ioctl error: %d\n", errno);
- X exit(1);
- X }
- X /* if TAB3 is set then setterm() wipes out tabs (ht) */
- X new_modes = old_modes;
- X new_modes.c_oflag &= ~TABDLY;
- X if (ioctl(fileno(stdin), TCSETAW, &new_modes) == -1)
- X {
- X printf("ioctl error: %d\n", errno);
- X exit(1);
- X }
- X#ifdef sequent
- X /* the sequent ATT emulation is broken soooo. */
- X old_modes.c_cflag &= ~(CSIZE | CSTOPB);
- X old_modes.c_cflag |= CS7 | PARENB;
- X#endif
- X catchsig();
- X tty_baud_rate = speeds[old_modes.c_cflag & CBAUD];
- X switch (old_modes.c_cflag & CSIZE) {
- X case CS5: tty_frame_size = 10; break;
- X case CS6: tty_frame_size = 12; break;
- X case CS7: tty_frame_size = 14; break;
- X case CS8: tty_frame_size = 16; break;
- X }
- X tty_frame_size += 2 +
- X ((old_modes.c_cflag & PARENB) ? 2 : 0) +
- X ((old_modes.c_cflag & CSTOPB) ? 4 : 2);
- X tty_abort = old_modes.c_cc[VINTR];
- X }
- X
- X
- X#else /* berkeley */
- X#define SLEEP(x) sleep(x)
- X#define TTY_IS_NOECHO !(new_modes.sg_flags & ECHO)
- X#define TTY_IS_OUT_TRANS ((new_modes.sg_flags & (CBREAK|RAW|CRMOD)) == CRMOD)
- X#define TTY_IS_CHAR_MODE ((new_modes.sg_flags & (CBREAK|RAW)) != 0)
- X
- Xstruct sgttyb old_modes, new_modes;
- X
- Xtty_raw(minch, mask)
- Xint minch, mask;
- X { /* set tty to raw noecho */
- X fflush(stdout);
- X new_modes = old_modes;
- X new_modes.sg_flags |= RAW;
- X new_modes.sg_flags &= ~(ALLDELAY | ECHO | CRMOD | CBREAK);
- X if (not_a_tty) return;
- X ioctl(fileno(stdin), TIOCSETP, &new_modes);
- X }
- X
- Xint
- Xtty_meta_prep()
- X { /* print a warning before the meta key test */
- X if (not_a_tty) return 0;
- X ptext("The meta key test must be run with the");
- X ptext(" terminal set for 8 data bits. Two stop bits");
- X ptext(" may also be needed for correct display.");
- X return 1;
- X }
- X
- Xextern short ospeed;
- X
- Xtty_set()
- X { /* set tty modes */
- X fflush(stdout);
- X new_modes = old_modes;
- X new_modes.sg_flags &= ~(ECHO | CRMOD | CBREAK | RAW);
- X if (select_delay_type == 0 & select_xon_xoff == 0)
- X {
- X new_modes.sg_flags |= RAW;
- X }
- X else new_modes.sg_flags |= CBREAK;
- X switch (select_delay_type) {
- X case 0:
- X new_modes.sg_flags &= ~(ALLDELAY);
- X break;
- X case 1:
- X new_modes.sg_flags &= ~(ALLDELAY);
- X new_modes.sg_flags |= NL2 | CR1;
- X break;
- X }
- X#ifdef TANDEM
- X switch (select_xon_xoff) {
- X case 0:
- X new_modes.sg_flags &= ~TANDEM;
- X break;
- X case 1:
- X new_modes.sg_flags |= TANDEM;
- X break;
- X }
- X#endif
- X if (select_pads == 1) ospeed = -1;
- X if (not_a_tty) return;
- X ioctl(fileno(stdin), TIOCSETP, &new_modes);
- X }
- X
- X
- Xtty_reset()
- X { /* reset the tty to the original modes */
- X fflush(stdout);
- X if (not_a_tty) return;
- X ioctl(fileno(stdin), TIOCSETP, &old_modes);
- X }
- X
- X
- Xtty_init()
- X { /* Berkeley Unix tty init */
- X struct tchars tc;
- X
- X not_a_tty = nodelay_read = FALSE;
- X if (ioctl(fileno(stdin), TIOCGETC, &tc) == -1)
- X {
- X if (errno == ENOTTY)
- X {
- X not_a_tty = TRUE;
- X return;
- X }
- X printf("ioctl error: %d\n", errno);
- X exit(1);
- X }
- X tty_abort = tc.t_intrc;
- X if (ioctl(fileno(stdin), TIOCGETP, &old_modes) == -1)
- X {
- X printf("ioctl error: %d\n", errno);
- X exit(1);
- X }
- X catchsig();
- X tty_baud_rate = speeds[old_modes.sg_ospeed];
- X tty_frame_size = 22; /* 8 data bits, 2 stop bits, 1 start bit */
- X tty_frame_size = 20; /* 8 data bits, 1 stop bit, 1 start bit */
- X#ifdef vax
- X tty_frame_size = 21; /* 8 data bits, 1.5 stop bits, 1 start bit */
- X#endif
- X if (ospeed < 0) ospeed = old_modes.sg_ospeed;
- X }
- X#endif
- X
- Xint
- Xstty_query(q)
- Xint q;
- X { /* return information about the terminal */
- X switch (q) {
- X case TTY_NOECHO:
- X return TTY_IS_NOECHO;
- X case TTY_OUT_TRANS:
- X return TTY_IS_OUT_TRANS;
- X case TTY_CHAR_MODE:
- X return TTY_IS_CHAR_MODE;
- X }
- X }
- X
- X#ifdef SELECT
- Xint
- Xchar_ready()
- X{
- X struct _timeval {
- X long tv_sec;
- X long tv_usec;
- X };
- X int ifds, ofds, efds, n;
- X struct _timeval tv;
- X
- X ifds = 1 << fileno(stdin);
- X ofds = efds = 0;
- X tv.tv_sec = 0;
- X tv.tv_usec = 200000;
- X n = select(20, &ifds, &ofds, &efds, &tv);
- X return (n != 0);
- X}
- X#else
- X#ifdef FIONREAD
- Xint
- Xchar_ready()
- X {
- X int i, j;
- X
- X /* the following loop has to be tuned for each computer */
- X for (j = 0; j < 1000; j++) {
- X ioctl(fileno(stdin), FIONREAD, &i);
- X if (i) return i;
- X }
- X return i;
- X }
- X#else
- X#define char_ready() 1
- X#endif
- X#endif
- X
- X
- Xnite_nite()
- X { /* go to sleep */
- X SLEEP(1);
- X }
- X
- X
- Xread_key(buf, max)
- Xchar *buf;
- Xint max;
- X { /* read one function key from the input stream */
- X int got, ask;
- X char *s;
- X
- X *buf = '\0';
- X s = buf;
- X fflush(stdout);
- X /* ATT unix may return 0 or 1, Berkeley Unix should be 1 */
- X while (read(fileno(stdin), s, 1) == 0);
- X ++s;
- X --max;
- X while (max > 0 && (ask = char_ready())) {
- X if (ask > max) ask = max;
- X if (got = read(fileno(stdin), s, ask)) s += got;
- X else break;
- X max -= got;
- X }
- X *s = '\0';
- X /* strip high order bits (if any) */
- X for (s = buf; *s; *s++ &= char_mask);
- X }
- X
- X
- Xignoresig( )
- X{
- X /* ignore signals */
- X signal(SIGINT, SIG_IGN);
- X signal(SIGHUP, SIG_IGN);
- X signal(SIGQUIT, SIG_IGN);
- X signal(SIGTERM, SIG_IGN);
- X}
- X
- X /* onintr( )
- X *
- X * is the interrupt handling routine
- X * onintr turns off interrupts while doing clean-up
- X *
- X * onintr always exits fatally
- X */
- X
- X
- Xonintr()
- X{
- X ignoresig();
- X tty_reset();
- X exit(1);
- X}
- X
- X
- X /* catchsig( )
- X *
- X * set up to field interrupts (via function onintr( ))
- X * so that if interrupted we can restore the correct terminal modes
- X *
- X * catchsig simply returns
- X */
- X
- X
- Xcatchsig( )
- X{
- X /* EXTERNAL VARIABLE USED */
- X extern onintr( );
- X
- X if ((signal(SIGINT, SIG_IGN)) == SIG_DFL)
- X signal(SIGINT, onintr);
- X
- X if ((signal(SIGHUP, SIG_IGN)) == SIG_DFL)
- X signal(SIGHUP, onintr);
- X
- X if ((signal(SIGQUIT, SIG_IGN)) == SIG_DFL)
- X signal(SIGQUIT, onintr);
- X
- X if ((signal(SIGTERM, SIG_IGN)) == SIG_DFL)
- X signal(SIGTERM, onintr);
- X
- X}
- END_OF_FILE
- if test 11601 -ne `wc -c <'sysdep.c'`; then
- echo shar: \"'sysdep.c'\" unpacked with wrong size!
- fi
- # end of 'sysdep.c'
- fi
- echo shar: End of archive 2 \(of 7\).
- cp /dev/null ark2isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 7 archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-